package com.excesys.exsecs.energy.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.excesys.exsecs.energy.entity.*;
import com.excesys.exsecs.energy.mapper.PowerExceptionFlowMapper;
import com.excesys.exsecs.energy.service.PowerExceptionFlowService;
import com.excesys.exsecs.energy.util.DateUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 能耗异常流水表
 *
 * @author lxc
 * @date 2024-03-19 16:31:56
 */
@Service
@RequiredArgsConstructor
public class PowerExceptionFlowServiceImpl extends ServiceImpl<PowerExceptionFlowMapper, PowerExceptionFlow> implements PowerExceptionFlowService {



	@Override
	public IPage queryPage(Page page, PowerExceptionFlow powerExceptionFlow) {

		if(StringUtils.isNotBlank(powerExceptionFlow.getStartTime())){
			String startTime = powerExceptionFlow.getStartTime();
			String endTime = powerExceptionFlow.getEndTime();
			if (powerExceptionFlow.getStartTime().matches("\\d{4}-\\d{2}")) {
				startTime = DateUtil.getFirstDayByMonth(startTime);
				endTime = DateUtil.getLastDayByMonth(endTime);

			}
			if (powerExceptionFlow.getStartTime().matches("\\d{4}")) {
				startTime = startTime + "-01-01";
				endTime = endTime + "-12-31";
			}
			powerExceptionFlow.setStartTime(startTime);
			powerExceptionFlow.setEndTime(endTime);
		}
		//查询能耗异常表
		IPage page1 = this.baseMapper.queryPage(page, powerExceptionFlow);
		return page1;
	}

	@Override
	public List<PowerExceptionFlow> queryList(PowerExceptionFlow powerExceptionFlow) {
		String startTime = powerExceptionFlow.getStartTime();
		String endTime = powerExceptionFlow.getEndTime();
		if (powerExceptionFlow.getStartTime().matches("\\d{4}-\\d{2}")) {
			startTime = DateUtil.getFirstDayByMonth(startTime);
			endTime = DateUtil.getLastDayByMonth(endTime);

		}
		if (powerExceptionFlow.getStartTime().matches("\\d{4}")) {
			startTime = startTime + "-01-01";
			endTime = endTime + "-12-31";
		}
		powerExceptionFlow.setStartTime(startTime);
		powerExceptionFlow.setEndTime(endTime);
		//查询能耗异常表
		List<PowerExceptionFlow> list = this.baseMapper.queryList(powerExceptionFlow);
		return list;
	}


}